ExtractFramesMemory(Stream,List<int>) Method

Summary

Extracts the specified frames from the input stream, and saves them to a new JPEG 2000 file in a byte array. This method is available in the Document/Medical Toolkits.

Syntax
C#
VB
C++
public byte[] ExtractFramesMemory( 
   Stream stream, 
   List<int> frames 
) 
  
Public Overloads Function ExtractFramesMemory( _ 
   ByVal stream As Stream, _ 
   ByVal frames As List(Of Integer) _ 
) As Byte() 
public: 
array<byte>^ ExtractFramesMemory(  
   Stream^ stream, 
   List<int>^ frames 
)  

Parameters

stream
A System.IO.Stream containing the JPEG 2000 file data from which the frames are being extracted.

frames
Frame indices. A list of integers specifying the indices of the frames to be extracted from the input file. All indices should be 0-based.

Return Value

A byte array that contains a JPEG 2000 file with extracted frames only.

Remarks

. This file contains only the extracted frame headers/code streams (not any obtained through the decompressing/recompressing process) so it saves processor time and memory.

This method is very suitable for server applications where multiple clients request specific frames of a JPEG 2000 file. Instead of decompressing and then recompressing the frames this method copies only the needed frame data, saving the data to a new JPEG 2000 file.

Example
C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Jpeg2000; 
 
public byte[] ExtractFramesMemoryStreamExample(List<int> frames) 
{ 
   FileStream fs = File.OpenRead(Path.Combine(LEAD_VARS.ImagesDir, "image1.jpx")); 
 
   Jpeg2000Engine engine = new Jpeg2000Engine(); 
   Jpeg2000FileInformation fileInfo = engine.GetFileInformation(fs); 
 
   for (int i = 0; i < frames.Count; i++) 
      if (frames[i] >= fileInfo.Frame.GetLength(0)) 
         return null; 
   byte[] buffer = engine.ExtractFramesMemory(fs, frames); 
   // Clean up 
   fs.Close(); 
   return buffer; 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Jpeg2000 
 
Private Function ExtractFramesMemoryStreamExample(ByVal frames As List(Of Integer)) As Byte() 
   Dim fs As FileStream = File.OpenRead(Path.Combine(LEAD_VARS.ImagesDir, "image1.jpx")) 
 
   Dim engine As New Jpeg2000Engine() 
   Dim fileInfo As Jpeg2000FileInformation = engine.GetFileInformation(fs) 
 
   For i As Integer = 0 To frames.Count - 1 
      If (frames(i) >= fileInfo.Frame.GetLength(0)) Then 
         Return Nothing 
      End If 
   Next i 
 
   Dim buffer() As Byte = engine.ExtractFramesMemory(fs, frames) 
 
   '  Clean up 
   fs.Close() 
   Return buffer 
End Function 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

Help Version 20.0.2020.3.31
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Jpeg2000 Assembly